package com.poetize.plus.entity.dto;

import com.poetize.plus.entity.po.Label;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Null;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Update;

/**
 * @Author zuosy
 * @Date 2024/3/30 16:54
 **/
public record LabelDTO(
        @Schema(description = "id")
        @Null(message = "id必须为空", groups = {Insert.class})
        @NotNull(message = "id不能为空", groups = {Update.class})
        Long labelId,

        @Schema(description = "分类ID")
        @NotNull(message = "分类id不能为空", groups = {Insert.class, Update.class})
        Long sortId,

        @Schema(description = "标签名称")
        @NotBlank(message = "标签名称不能为空", groups = {Insert.class, Update.class})
        String labelName,

        @Schema(description = "标签描述")
        @NotBlank(message = "标签描述不能为空", groups = {Insert.class, Update.class})
        String labelDescription
) {
    /**
     * DTO转实体类
     *
     * @param labelDTO
     * @return
     */
    public static Label convertDTO(LabelDTO labelDTO) {
        return new Label(labelDTO.labelId, labelDTO.sortId, labelDTO.labelName, labelDTO.labelDescription);
    }
}
